package action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import pageModel.Json;
import pageModel.Receipt;
import service.ReceiptServiceI;

import com.opensymphony.xwork2.ModelDriven;
@Namespace("/")
@Action(value="receiptAction")
public class ReceiptAction extends BaseAction implements ModelDriven<Receipt>{
Receipt receipt=new Receipt();
private ReceiptServiceI receiptService;

	public ReceiptServiceI getReceiptService() {
	return receiptService;
}
@Autowired
public void setReceiptService(ReceiptServiceI receiptService) {
	this.receiptService = receiptService;
}

	@Override
	public Receipt getModel() {
		// TODO Auto-generated method stub
		return receipt;
	}
public void save(){
	Json j=new Json();
	try{
		receiptService.saveOrUpdate(receipt);
		j.setSuccess(true);
		j.setMsg("结账成功!");
	}catch(Exception e){
		j.setMsg("结账失败!");
	}
	super.writeJson(j);
}
public void datagrid(){
	super.writeJson(receiptService.datagrid(receipt));
}
public void show(){
	super.writeJson(receiptService.show(receipt.getCashier(),receipt));
}
}

